package com.ihr360.excel.service.convertor;

import com.google.common.collect.Lists;
import com.ihr360.commons.lang.CollectionUtils;
import com.ihr360.commons.model.IConvertor;
import com.ihr360.excel.entity.CorrectSpreadsheetRowEntity;
import com.ihr360.excel.model.dto.CorrectSpreadsheetRow;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author richey
 */
@Component
public class SpreadsheetRowConvertor implements IConvertor<CorrectSpreadsheetRowEntity, CorrectSpreadsheetRow> {

    @Override
    public CorrectSpreadsheetRow convertEntityToDto(CorrectSpreadsheetRowEntity entity) {
        return null;
    }

    @Override
    public CorrectSpreadsheetRowEntity convertDtoToEntity(CorrectSpreadsheetRow dto) {
        if (dto == null) {
            return null;
        }
        CorrectSpreadsheetRowEntity entity = new CorrectSpreadsheetRowEntity();
        BeanUtils.copyProperties(dto, entity);
        return entity;
    }

    public List<CorrectSpreadsheetRowEntity> convertDtosToEntities(List<CorrectSpreadsheetRow> dtos,final List<String> dateHeaders) {
        if (CollectionUtils.isEmpty(dtos)) {
            return Lists.newArrayList();
        }
        List<CorrectSpreadsheetRowEntity> entities = Lists.newArrayListWithCapacity(dtos.size());
        dtos.forEach(dto -> {
            entities.add(convertDtoToEntity(dto));
        });
        return entities;
    }
}
